package com.viettel.rmsmobile;

import java.util.ArrayList;
import java.util.List;

import com.viettel.BO.CandidateBean;
import com.viettel.BO.RecruitmentAnouncementBean;
import com.viettel.data.CandidateFetcher;
import com.viettel.synctask.CandidateSyncTask;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

public class CandidateCareerFragment extends Fragment {
	public static final String ARG_POSITION = "position_menu";

	private CandidateCareerAdapter adapter;
	private ListView listFindJob;
	private List<CandidateBean> jobList = new ArrayList();
	private CandidateFetcher candidateFetcher;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View findJobView = inflater.inflate(R.layout.candidate_carrer_job,
				container, false);
		int i = getArguments().getInt(ARG_POSITION);
		listFindJob = (ListView) findJobView.findViewById(R.id.listJob);
		CandidateSyncTask syncTask = new CandidateSyncTask();
		syncTask.execute(this, 24957L);
		return findJobView;
	}

	public void setJoblist(List<CandidateBean> response) {
		jobList = response;
		setView();
	}

	private void setView() {
		if (jobList != null && !jobList.isEmpty()) {
			adapter = new CandidateCareerAdapter(getActivity(),
					R.layout.item_candidate_carrer, jobList);
			// View List
			listFindJob.setAdapter(adapter);
			listFindJob.setOnItemClickListener(new FindJobClickListener());
		}
	}

	private class FindJobClickListener implements ListView.OnItemClickListener {
		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			selectJob(position);
		}
	}

	private void selectJob(int position) {
		Intent i = new Intent(getActivity(), ViewJobDetailActivity.class);
		CandidateBean item = jobList.get(position);
		i.putExtra("positionName", item.getPositionName());
		i.putExtra("organizationName", item.getOrganizationName());
		i.putExtra("status", item.getStatus());
		i.putExtra("jobDescription", item.getJobDescription());
		this.startActivity(i);
	}

}
